package com.cz.ssyx.sys.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cz.ssyx.common.result.Result;
import com.cz.ssyx.model.sys.Ware;
import com.cz.ssyx.sys.service.WareService;
import com.cz.ssyx.vo.product.WareQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 仓库表 前端控制器
 * </p>
 *
 * @author Joker
 * @since 2024-04-17
 */
@Api(tags = "仓库管理接口")
//@CrossOrigin
@RestController
@RequestMapping("/admin/sys/ware")
public class WareController {

    @Autowired
    private WareService wareService;

    @ApiOperation("分页查询仓库列表")
    @GetMapping("/{page}/{limit}")
    public Result pageList(@PathVariable Long page, @PathVariable Long limit,
                           WareQueryVo wareQueryVo) {
        String name = wareQueryVo.getName();

        Page<Ware> warePage = new Page<>(page, limit);

        LambdaQueryWrapper<Ware> queryWrapper = new LambdaQueryWrapper<>();
        if (!StringUtils.isEmpty(name)) {
            queryWrapper.like(Ware::getName, name);
        }

        Page<Ware> resultPage = wareService.page(warePage, queryWrapper);

        return Result.ok(resultPage);
    }

    @ApiOperation("查询列表")
    @GetMapping("findAllList")
    public Result findAllList() {
        List<Ware> list = wareService.list();
        return Result.ok(list);
    }
}

